package application

import (
	"FlowMaster/logger"
	"FlowMaster/model"
	"FlowMaster/service"
)

// t
var loggerI = logger.Get()

func UploadDataRun(y model.Yunyouqilu, totle int, out int, real int) error {
	// 获取token

	asscesToken, err := service.CheckAccessToken(y.BaseURL, y.Appkey, y.Appsecret)
	if err != nil {
		loggerI.Error("获取token失败", err)
		return err
	}
	// 获取景区ID
	ScenicId, err := service.GetScenicID(y.BaseURL, y.LibraryName)
	if err != nil {
		loggerI.Error("获取景区ID失败", err)
		return err
	}
	loggerI.Debug("获取景区信息", ScenicId)

	body := model.NewUploadDataRequest(ScenicId, y.Notice, totle, out, real)
	loggerI.Info("上传数据", body)
	data, err := service.UploadData(y.BaseURL, asscesToken, body)
	if err != nil {
		loggerI.Error("上传数据失败", err)
		return err
	}
	loggerI.Debug("上传数据", data)

	if data.Status_code == 200 {
		loggerI.Info("上传数据成功")
	} else {
		loggerI.Error("上传数据失败", data.Message)
	}
	return nil
}
